if(!jsx3.lang.Class.forName("tibco.admin.enterpriseAssets.servers.plugins.Plugins")) {
    tibco.admin.Main.loadResource("tibco/admin/enterpriseAssets/servers/plugins/jss/jss.xml", "tibco.admin", "jss22C", "ljss", false);
    tibco.admin.Main.loadResource("tibco/admin/enterpriseAssets/servers/plugins/jss/xslt.xml", "tibco.admin", "xslt22C", "jss", false);

    /**
     **/
    jsx3.Class.defineClass(
            'tibco.admin.enterpriseAssets.servers.plugins.Plugins',
            jsx3.gui.LayoutGrid,
            null,
            function(plugin) {

                plugin.prototype.subscribeAll = function() {
                    this.mtxList = this.getDescendantOfName("mtxDeployedPlugins900G");
                    this.callgetInstalledPlugins();
                }

                plugin.prototype.callgetInstalledPlugins = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin",
                            "tibco/admin/enterpriseAssets/servers/plugins/rules/getPluginListRules.xml",
                            "getInstalledPlugins",
                            "get installed plugins");
                    //subscribe and call
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, this, this.ongetInstalledPluginsSuccess);
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getPluginsEndpointURL())
                    objService.doCall();
                };

                plugin.prototype.ongetInstalledPluginsSuccess = function(objEvent) {
                    this.mtxList.repaint();
                    var cacheDoc = this.mtxList.getXML();
                    if(cacheDoc) {
                        if(this.selection != null) {
                            var iter = this.selection.iterator();
                            while(iter.hasNext()) {
                                var name = iter.next();
                                var record = this.mtxList.getXML().selectSingleNode("//record[@name='" + name + "']");
                                if(record) {
                                    record.setAttribute("jsxselected", 1);
                                }
                            }
                            this.selection = null;
                        }
                    }
                    this.updateButtons();
                };

                plugin.prototype.calldeployPlugins = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin",
                            "tibco/admin/enterpriseAssets/servers/plugins/rules/deployPluginsRules.xml",
                            "deployPlugins",
                            "deploy plugins");
                    //subscribe and call
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, this, this.ondeployPluginsSuccess);
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getPluginsEndpointURL())
                    objService.doCall();
                };

                plugin.prototype.ondeployPluginsSuccess = function(objEvent) {
                    this.callgetInstalledPlugins();
                };

                plugin.prototype.tryToUndeployPlugins = function() {
                    var cacheRecords = this.mtxList.getXML().getRootNode().selectNodes("//record[@jsxselected='1']");
                    tibco.admin.util.Log.SERVICE.trace(tibco.admin.Main.getServer().getDynamicProperty("@@NumberOfSelected900G") + " [\n" + cacheRecords.getLength() + "]");
                    if(cacheRecords.getLength() == 0) {
                        tibco.admin.Main.alert(tibco.admin.Main.getServer().getDynamicProperty("@@NoSelected900G"), tibco.admin.Main.getServer().getDynamicProperty("@@Select2Undeploy900G"));
                        return;
                    }
                    this.callundeployPlugins();
                }

                plugin.prototype.callundeployPlugins = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin",
                            "tibco/admin/enterpriseAssets/servers/plugins/rules/undeployPluginsRules.xml",
                            "undeployPlugins",
                            "undeploy plugins");
                    //subscribe and call
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, this, this.onundeployPluginsSuccess);
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getPluginsEndpointURL())
                    objService.doCall();
                };

                plugin.prototype.onundeployPluginsSuccess = function(objEvent) {
                    this.callgetInstalledPlugins();

                };

                plugin.prototype.tryToStartPlugins = function() {
                    var cacheRecords = this.mtxList.getXML().getRootNode().selectNodes("//record[@jsxselected='1']");
                    tibco.admin.util.Log.SERVICE.trace(tibco.admin.Main.getServer().getDynamicProperty("@@NumberOfSelected900G") + " [\n" + cacheRecords.getLength() + "]");
                    if(cacheRecords.getLength() == 0) {
                        tibco.admin.Main.alert(tibco.admin.Main.getServer().getDynamicProperty("@@NoSelected900G"), tibco.admin.Main.getServer().getDynamicProperty("@@Select2Start900G"));
                        return;
                    }
                    this.callstartPlugins();
                }

                plugin.prototype.nodeSelected = function() {
                    this.updateButtons();
                }

                plugin.prototype.updateButtons = function() {
                    var nodes = this.mtxList.getSelectedNodes();
                    var count = nodes.size();
                    var notOwner = 0;
                    var running = 0;
                    var stopped = 0;
                    var unknown = 0;
                    var iter = nodes.iterator();
                    while(iter.hasNext()) {
                        var node = iter.next();
                        var state = node.getAttribute("state");
                        if(node.getAttribute("hasOwner") != "true") {
                            notOwner++;
                        }
                        switch(state) {
                            case "Running":
                                running++;
                                break;
                            case "Stopped":
                                stopped++;
                                break;
                            case "Unknown":
                                unknown++;
                                break;
                            default:
                                unknown++;
                                break;
                        }
                    }
                    tibco.admin.Main.getServer().getJSXByName("btnUndeployPlugin_900G").setEnabled(((count > 0) && (notOwner == 0)) ? jsx3.gui.Form.STATEENABLED : jsx3.gui.Form.STATEDISABLED, true);
                    tibco.admin.Main.getServer().getJSXByName("btnStartPlugin_900G").setEnabled(((count > 0) && ((stopped + unknown) == count)) ? jsx3.gui.Form.STATEENABLED : jsx3.gui.Form.STATEDISABLED, true);
                    tibco.admin.Main.getServer().getJSXByName("btnStopPlugin_900G").setEnabled(((count > 0) && ((running + unknown) == count)) ? jsx3.gui.Form.STATEENABLED : jsx3.gui.Form.STATEDISABLED, true);

                }

                plugin.prototype.callstartPlugins = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin",
                            "tibco/admin/enterpriseAssets/servers/plugins/rules/startPluginsRules.xml",
                            "startPlugins",
                            "start plugins");
                    //subscribe and call
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, this, this.onstartPluginsSuccess);
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getPluginsEndpointURL())
                    objService.doCall();
                };

                plugin.prototype.onstartPluginsSuccess = function(objEvent) {
                    this.callgetInstalledPlugins();
                };

                plugin.prototype.tryToStopPlugins = function() {
                    var cacheRecords = this.mtxList.getXML().getRootNode().selectNodes("//record[@jsxselected='1']");
                    tibco.admin.util.Log.SERVICE.trace(tibco.admin.Main.getServer().getDynamicProperty("@@NumberOfSelected900G") + " [\n" + cacheRecords.getLength() + "]");
                    if(cacheRecords.getLength() == 0) {
                        tibco.admin.Main.alert(tibco.admin.Main.getServer().getDynamicProperty("@@NoSelected900G"), tibco.admin.Main.getServer().getDynamicProperty("@@Select2Stop900G"));
                        return;
                    }
                    this.callstopPlugins();
                }

                plugin.prototype.callstopPlugins = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin",
                            "tibco/admin/enterpriseAssets/servers/plugins/rules/stopPluginsRules.xml",
                            "stopPlugins",
                            "stop plugins");
                    //subscribe and call
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, this, this.onstopPluginsSuccess);
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getPluginsEndpointURL())
                    objService.doCall();
                };

                plugin.prototype.onstopPluginsSuccess = function(objEvent) {
                    this.callgetInstalledPlugins();
                };

                plugin.prototype.deployNewPlugin = function() {
                    var me = this;
                    tibco.admin.Main.loadUIResourceAsync(tibco.admin.Main.getServer().getBodyBlock(), "tibco.admin", "tibco/admin/enterpriseAssets/servers/plugins/components/dialog.xml", me, me.dialogLoaded, true);
                    //tibco.admin.Main.getServer().getJSXByName("blkUpload900G").setText("<form method='POST' enctype='multipart/form-data' action='http://localhost:8120/amxadministrator/pluginupload/abc'><input type=file name=upfile><br><br><input type=submit value=Upload></form>", true);
                }

                plugin.prototype.dialogLoaded = function(objEvent) {
                    objEvent.obj.papa = this;
                    //objEvent.obj.getDescendantOfName("").setText("<form method='POST' enctype='multipart/form-data' action='" + "/" + this.getAdminWebapp() + "/pluginupload/abc'><input type=file name=upfile>");
                };

                plugin.prototype.onRefresh = function() {
                    var selectionSize = this.mtxList.getSelectedNodes().size();
                    if(selectionSize > 0) {
                        this.selection = new jsx3.util.List(selectionSize);
                        var nodes = this.mtxList.getSelectedNodes();
                        for(var i = 0; i < nodes.size(); i++) {
                            this.selection.add(nodes.getItem(i).getAttribute('name'));
                        }
                    }
                    this.callgetInstalledPlugins();
                }



                /****************************************************************
                 *  Set permission and remove permission
                 *  Author: Ramin Danaei Boroumand
                 *  Date: 06-29-2007
                 ****************************************************************/

                plugin.prototype.loadPermissionButtons = function() {
                    var domNode = this.getDescendantOfName("blkPermissionsContainer_900G")
                    this.permissions = tibco.admin.Main.loadUIResource(domNode, "tibco.admin", "tibco/admin/enterpriseAssets/userMgt/window/permissions/ui/setPermissions.xml", true)
                    this.mtxList = this.getDescendantOfName("mtxDeployedPlugins900G");
                    this.permissions.initialize("Plugin", "entityID", "name", this.mtxList)
                    var me = this
                    this.mtxList.switchPermissionBtn = function() {
                        me.permissions.switchPermissionBtn()
                    }
                }

            });
}